colorplane: Convert crosshair rendering to snapshot
authorTimm Bäder <tbaeder@redhat.com>
Fri, 23 Nov 2018 10:22:51 +0000 (11:22 +0100)
committerTimm Bäder <mail@baedert.org>
Tue, 27 Nov 2018 04:37:38 +0000 (05:37 +0100)
This is slightly different than the cairo version since the
half-transparent lines now overlap but nobody can see that anyway.

gtk/gtkcolorplane.c

index 1eedf04f66091b44ffe926355a6d35540c1f9734..17f658c9aced829bfa7c3d931d5ac177bd96ee72 100644 (file)
@@ -72,7 +72,6 @@ plane_snapshot (GtkWidget   *widget,
   GtkColorPlane *plane = GTK_COLOR_PLANE (widget);
   gint x, y;
   gint width, height;
-  cairo_t *cr;
 
   sv_to_xy (plane, &x, &y);
   width = gtk_widget_get_width (widget);
@@ -81,33 +80,34 @@ plane_snapshot (GtkWidget   *widget,
   gtk_snapshot_append_texture (snapshot,
                                plane->priv->texture,
                                &GRAPHENE_RECT_INIT (0, 0, width, height));
-  cr = gtk_snapshot_append_cairo (snapshot,
-                                  &GRAPHENE_RECT_INIT (0, 0, width, height));
-
-  cairo_move_to (cr, 0,     y + 0.5);
-  cairo_line_to (cr, width, y + 0.5);
-
-  cairo_move_to (cr, x + 0.5, 0);
-  cairo_line_to (cr, x + 0.5, height);
-
   if (gtk_widget_has_visible_focus (widget))
     {
-      cairo_set_line_width (cr, 3.0);
-      cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.6);
-      cairo_stroke_preserve (cr);
-
-      cairo_set_line_width (cr, 1.0);
-      cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.8);
-      cairo_stroke (cr);
+      const GdkRGBA c1 = { 1.0, 1.0, 1.0, 0.6 };
+      const GdkRGBA c2 = { 0.0, 0.0, 0.0, 0.8 };
+
+      /* Crosshair border */
+      gtk_snapshot_append_color (snapshot, &c1,
+                                 &GRAPHENE_RECT_INIT (0, y - 1.5, width, 3));
+      gtk_snapshot_append_color (snapshot, &c1,
+                                 &GRAPHENE_RECT_INIT (x - 1.5, 0, 3, height));
+
+      /* Actual crosshair */
+      gtk_snapshot_append_color (snapshot, &c2,
+                                 &GRAPHENE_RECT_INIT (0, y - 0.5, width, 1));
+      gtk_snapshot_append_color (snapshot, &c2,
+                                 &GRAPHENE_RECT_INIT (x - 0.5, 0, 1, height));
     }
   else
     {
-      cairo_set_line_width (cr, 1.0);
-      cairo_set_source_rgba (cr, 0.8, 0.8, 0.8, 0.8);
-      cairo_stroke (cr);
+      const GdkRGBA c = { 0.8, 0.8, 0.8, 0.8 };
+
+      /* Horizontal */
+      gtk_snapshot_append_color (snapshot, &c,
+                                 &GRAPHENE_RECT_INIT (0, y - 0.5, width, 1));
+      /* Vertical */
+      gtk_snapshot_append_color (snapshot, &c,
+                                 &GRAPHENE_RECT_INIT (x - 0.5, 0, 1, height));
     }
-
-  cairo_destroy (cr);
 }
 
 static void